package com.bj58.data.emailreports.sends;

import java.util.Date;
import java.util.List;

import com.bj58.data.emailreports.controllers.NetflowWeekReportController;
import com.bj58.data.emailreports.model.EmailReportUser;
import com.bj58.data.emailreports.utils.DateUtil;

public class NetflowWRSend extends BaseSend{

	public static void main(String[] args) {
		NetflowWRSend  fs = new NetflowWRSend();
		NetflowWeekReportController  wk = new NetflowWeekReportController();
		try {
			//执行日期   
			String searchDate = DateUtil.getStringDate(new Date(),"yyyy-MM-dd");
			
			//发送类型   all:part1-1  / 1:part1  
			String sendType = "all";
			
			if(null != args && args.length > 0){
				if(args.length != 2){
					System.out.println("params error ! ");
					System.exit(0);
				}
				
				if(args[0].contains("-")){
					searchDate = args[0].trim();
				}
				
				sendType = args[1].trim();
			}
			
			//searchDate="2016-03-21 ";//周一
			//sendType="4";
			System.out.println(searchDate);
			System.out.println(sendType);
							
			String beginDate = DateUtil.getStringDate(DateUtil.getDateBefore(DateUtil.strToDate(searchDate, "yyyy-MM-dd"), 7),"yyyy-MM-dd");
			String endDate = DateUtil.getStringDate(DateUtil.getDateBefore(DateUtil.strToDate(searchDate, "yyyy-MM-dd"), 1),"yyyy-MM-dd");
	
			System.out.println(" from " + beginDate + " to " + endDate);
			
			String contextDayReport = "";

			//part 1
			if("all".equals(sendType.toLowerCase()) || "1".equals(sendType)){
				contextDayReport = wk.weekReportPartOne(endDate);
				List<EmailReportUser> userListDayReport = fs.getUsersBySendType(60);//收件人
				if("".equals(contextDayReport)){
					fs.errorWarn("流量数据周报--全站 from "+ beginDate + " to " + endDate );
				}else{
					fs.ReportSend(userListDayReport, "流量数据周报--全站 from "+ beginDate + " to " + endDate, contextDayReport, null);
				}
			}
			
			//part 2
			if("all".equals(sendType.toLowerCase()) || "2".equals(sendType)){
				contextDayReport = wk.weekReportPartTwo(endDate,"zhaopin");
				List<EmailReportUser> userListDayReport = fs.getUsersBySendType(62);//收件人
				if("".equals(contextDayReport)){
					fs.errorWarn("流量数据周报--招聘 from "+ beginDate + " to " + endDate );
				}else{
					fs.ReportSend(userListDayReport, "流量数据周报--招聘 from "+ beginDate + " to " + endDate, contextDayReport, null);
				}
			}
			
			//part 3
			if("all".equals(sendType.toLowerCase()) || "3".equals(sendType)){
				contextDayReport = wk.weekReportPartTwo(endDate,"huangye");
				List<EmailReportUser> userListDayReport = fs.getUsersBySendType(61);//收件人
				if("".equals(contextDayReport)){
					fs.errorWarn("流量数据周报--黄页 from "+ beginDate + " to " + endDate );
				}else{
					fs.ReportSend(userListDayReport, "流量数据周报--黄页 from "+ beginDate + " to " + endDate, contextDayReport, null);
				}
			}
			
			//part 4
			if("all".equals(sendType.toLowerCase()) || "4".equals(sendType)){
				contextDayReport = wk.weekReportPartTwo(endDate,"ershouchuangxin");
				List<EmailReportUser> userListDayReport = fs.getUsersBySendType(63);//收件人
				if("".equals(contextDayReport)){
					fs.errorWarn("流量数据周报--二手创新 from "+ beginDate + " to " + endDate );
				}else{
					fs.ReportSend(userListDayReport, "流量数据周报--二手创新 from "+ beginDate + " to " + endDate, contextDayReport, null);
				}
			}
				

		} catch (Exception e) {
			e.printStackTrace();
			fs.errorWarn("流量数据周报报错!");
		}finally{
			System.exit(0);
		}
	}
	
}
